/*
  Programa Wifis, 2010-2011
  Autor: Nilhcraiv

This file is part of Wifis.

    Wifis is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Wifis is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Wifis.  If not, see <http://www.gnu.org/licenses/>.
*/
#include "options.h"
#include "ui_options.h"
#include <QMessageBox>

options::options(QWidget *parent, save *classSave, QVector<int> *conf) :
    QDialog(parent), configuracion(conf),
    ui(new Ui::options)
{
    ui->setupUi(this);
    this->claseSave = classSave;

    setWindowTitle("Opciones");

    connect(ui->cancelButton,SIGNAL(clicked()),this,SLOT(slotCancelButton()));
    connect(ui->okButton,SIGNAL(clicked()),this,SLOT(slotOkButton()));
}

options::~options()
{
    delete ui;
}

void options::slotCancelButton()
{
    this->hide();

    this->ui->tabWidget->setCurrentWidget(this->ui->tab);

    if(configuracion->isEmpty())
        return;

    if(configuracion->at(0)==0){//comprobar actualizaciones al inicio
        this->ui->checkBox->setChecked(false);}
    else{
        this->ui->checkBox->setChecked(true);}
    if(configuracion->at(1)==0){//Iniciar maximizado
        this->ui->checkBox_2->setChecked(false);}
    else{
        this->ui->checkBox_2->setChecked(true);}
    if(configuracion->at(2)==0){//Enviar estadisticas anonimas
        this->ui->checkBox_3->setChecked(false);}
    else{
        this->ui->checkBox_3->setChecked(true);}
    if(configuracion->at(3)==0){//Detectar redes al iniciar la aplicacion
        this->ui->checkBox_4->setChecked(false);}
    else{
        this->ui->checkBox_4->setChecked(true);}
    if(configuracion->at(4)==0){//Modo monitor
        this->ui->checkBox_5->setChecked(false);}
    else{
        this->ui->checkBox_5->setChecked(true);}

    this->ui->doubleSpinBox->setValue(configuracion->at(5));

}//slotCancelButton

void options::slotOkButton()
{
    this->hide();

    if(this->ui->checkBox->isChecked()){
        config.push_back(1);}
    else{
        config.push_back(0);}
    if(this->ui->checkBox_2->isChecked()){
        config.push_back(1);}
    else{
        config.push_back(0);}
    if(this->ui->checkBox_3->isChecked()){
        config.push_back(1);}
    else{
        config.push_back(0);}
    if(this->ui->checkBox_4->isChecked()){
        config.push_back(1);}
    else{
        config.push_back(0);}
    if(this->ui->checkBox_5->isChecked()){
        config.push_back(1);}
    else{
        config.push_back(0);}

    config.push_back(this->ui->doubleSpinBox->value());


    claseSave->guardarConfiguracion(config);

    config.clear();

    QMessageBox::information(this,"Información","Todos los cambios realizados tendran efecto tras"
                             " reiniciar la aplicación.","Aceptar");

    this->ui->tabWidget->setCurrentWidget(this->ui->tab);
}//slotOkButon

void options::setChecked_1(bool check)
{
    this->ui->checkBox->setChecked(check);
}

void options::setChecked_2(bool check)
{
    this->ui->checkBox_2->setChecked(check);
}

void options::setChecked_3(bool check)
{
    this->ui->checkBox_3->setChecked(check);
}

void options::setChecked_4(bool check)
{
    this->ui->checkBox_4->setChecked(check);
}

void options::setChecked_5(bool check)
{
    this->ui->checkBox_5->setChecked(check);
}

void options::setValueDoubleSpinBox(double value)
{
    this->ui->doubleSpinBox->setValue(value);
}
